<html>
<head>
    <title>添加</title>
    <meta charset="UTF-8">
</head>
<link rel="stylesheet" href="/static/layui/css/layui.css" />
<body>

<form class="layui-form"  action="" lay-filter="edit">
    <div class="layui-form-item">
        <div class="layui-input-inline layui-col-md1">
            <input type="hidden" name="pid" id="pid" lay-verify="required" autocomplete="off"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户编号：</label>
        <div class="layui-input-inline layui-col-md8">
            <input type="text" name="puser" id="puser"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码：</label>
        <div class="layui-input-inline layui-col-md7">
            <input type="text" name="ppassword" id="ppassword"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名：</label>
        <div class="layui-input-inline layui-col-md1">
            <input type="text" name="pname" id="pname"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号：</label>
        <div class="layui-input-inline layui-col-md3">
            <input type="text" name="pphone" id="pphone"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱：</label>
        <div class="layui-input-inline layui-col-md3">
            <input type="text" name="pemail" id="pemail"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别：</label>
        <div class="layui-input-inline layui-col-md3">
            <input type="text" name="psex" id="psex"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址：</label>
        <div class="layui-input-inline layui-col-md3">
            <input type="text" name="paddress" id="paddress"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">注册时间：</label>
        <div class="layui-input-inline layui-col-md3">
            <input type="text" name="ptime" id="ptime"  required  lay-verify="required" placeholder="..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">治疗医生：</label>
        <div class="layui-input-inline layui-col-md3">
            <select id="did" name="did">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
</body>

<script src="/static/js/system.js"></script>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    //Demo
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;
        //动态选择医生下拉列表
        $.ajax({
            url: "/queryDoctorAll.do",
            dataType: "json",
            success:function (rs) {
                console.log(rs);
                if (rs.code==0){
                    console.log(rs);
                    $.each(rs.data, function (index, item) {
                        // 追加option节点
                        //item.name是option里的文本值
                        //item.id是option的value值
                        $("#did").append(new Option(item.dname, item.did));
                    });
                    form.render('select');
                }
            }
        });
        $.ajax({
            url:'/queryOne.do',
            dataType:"json",
            data:{"id":getQueryString("id")},
            success:function (da) {
                console.log(da);
                if (da.code == 0) {
                        // form.val("edit",da.data);
                    $.each(da.data,function (index,i) {
                        form.val("edit", i);
                        $('#ptime').val(layui.util.toDateString(i.ptime,'yyyy-MM-dd'));
                    })
                } else {
                    layer.msg("查询数据失败！");
                }
            }
        });
        //监听提交 15039939677
        form.on('submit(formDemo)', function(data){
            var data1 = form.val("edit");
            console.log(data1);
            $.ajax({
                url:'/upd.do',
                type:"post",
                data:data1,
                dataType:"json",
                success:function (da) {
                    if (da.code == 0) {
                        console.log(da);
                        layer.alert("修改成功！", function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg("修改失败！");
                    }
                }
            });
            return false;
        });
        laydate.render({
            elem: '#ptime'    //指定元素test1
        });
    });
</script>
</html>
